const multer = require('multer');
//简单写法
// const upload = multer({ dest: 'uploads/' })
//完整写法
const storage = multer.diskStorage({
    destination: function (req, file, cb) { //文件存储的位置
        cb(null, './public/images/upload')
    },
    filename: function (req, file, cb) { //设置文件名
        //文件名要根据业务需求。
        let name = file.originalname
        let index = name.lastIndexOf('.');
        cb(null, name.substring(0, index) + Date.now() + name.substring(index))
    }
})
const upload = multer({ storage: storage });
module.exports = upload;
